package com.gm.manager.common.tools;

import com.gm.manager.module.login.entity.LoginBack;
import com.gm.manager.module.login.service.LoginService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author zhuZhaoYang
 * @date 2021/8/7 13:27
 */
@Component
public class LoginUtils {

    private LoginService loginService;

    @Autowired
    public void setLoginService(LoginService loginService) {
        this.loginService = loginService;
    }

    public static LoginUtils loginUtils = new LoginUtils();

    @PostConstruct
    public void init() {
        loginUtils.loginService = this.loginService;
    }

    public static String md5(String password, String salt) {
        return new Md5Hash(password, salt).toHex();
    }

    public static LoginBack checkLogin(String token) {
        return loginUtils.loginService.checkLogin(token);
    }
}
